<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<style>
	#div1 { width: 200px; height: 200px; position: absolute; background: red;}	
</style>
<script>
	
window.onload = function()
{
		var timer =null;
		var oBtn = document.getElementById('btn1');
		var oDiv1 = document.getElementById('div1');
	
		oBtn.onclick = function(){ StartMove();};
	
		function StartMove()
		{
				var speed = 1;
				
			
				clearInterval(timer);
				timer =setInterval(function()
					{ 

					if(oDiv1.offsetLeft>=300)
					{
							clearInterval(timer);
					}
					else
						{
							oDiv1.style.left = oDiv1.offsetLeft + speed + 'px';
						}
																						},
																						50);
		}
};
</script>
</head>

<body>
<input type="button" id="btn1" value="运动">
<div id="div1"></div>
</body>
</html>
